Generate Spring Security wiring through the beans DSL - #16119
Open
codeconsole wants to merge 3 commits into
Open
Generate Spring Security wiring through the beans DSL#16119codeconsole wants to merge 3 commits into
codeconsole wants to merge 3 commits into
Conversation
The spring-boot-starter-security feature generated a separate SecurityConfig class and pulled it into the application with @import(SecurityConfig). Declare the same two beans through the beans DSL on the generated Application class instead: one fewer file, and the security wiring sits where an application's other bean wiring goes. grails-core exports grails-beans-dsl as an api dependency, so a generated application needs no declaration of its own for the DSL. Also mark the User domain's password field with the password constraint so scaffolding masks it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16119 +/- ##
==================================================
+ Coverage 52.3431% 52.3435% +0.0004%
- Complexity 18296 18302 +6
==================================================
Files 2036 2036
Lines 96347 96373 +26
Branches 16829 16836 +7
==================================================
+ Hits 50431 50445 +14
- Misses 38492 38502 +10
- Partials 7424 7426 +2 🚀 New features to boost your workflow:
|
The generated filter chain permitted every request. That left the scaffolded user admin at /user/** open to anonymous visitors, and made an app generated with the security feature less restrictive than one generated with no security configuration at all, since Spring Boot's own default authenticates everything. Permit the home page, the error page and static assets, require ROLE_ADMIN for /user/**, and authenticate everything else - the same shape the Grails Spring Security feature already configures through staticRules, so the two security features no longer disagree about whether a generated app is open or closed.
BootStrap seeded a single admin user, so every account in a freshly generated app held ROLE_ADMIN and nothing exercised the distinction the generated URL rules draw between ROLE_ADMIN and an ordinary logged-in user. Seed a second ROLE_USER account alongside it. The delegating password encoder moves to a local so both accounts share one instance.
✅ All tests passed ✅🏷️ Commit: 7fbe45e Learn more about TestLens at testlens.app. |
codeconsole
requested review from
borinquenkid,
jamesfredley,
jdaugherty,
matrei and
sbglasius
August 9, 2026 21:22
jdaugherty
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two changes to the
spring-boot-starter-securityforge feature.1. Wire the security beans through the
beansDSLThe feature generated a separate
SecurityConfigclass and pulled it into the generated app with@Import(SecurityConfig). This declares the same two beans through thebeansDSL (#16019) on the generatedApplicationclass instead, and deletes theSecurityConfigtemplate.No dependency declaration is added to the generated build:
grails-corealready exportsgrails-beans-dslas anapidependency, so the transform reaches any app that depends ongrails-core.Applications generated without the feature are unaffected —
application.rocker.rawrenders byte-identical output for them.2. Lock down the generated defaults
The generated filter chain used
anyRequest().permitAll(). That left the scaffolded user admin at/user/**open to anonymous visitors, and made an app generated with the security feature less restrictive than one generated with no security configuration at all, since Spring Boot's own default authenticates everything.The new rules match the shape the Grails Spring Security feature already configures through
staticRules, so the two security features no longer disagree about whether a generated app is open or closed.ROLE_ADMINis whatbootStrap.rocker.rawseeds.Two deliberate departures from that feature's list:
/shutdownis not permitted, and/**/js/**,/**/css/**,/**/images/**and/**/favicon.icoare left out because asset-pipeline serves all of them under/assets/**.Result
A generated secured app, with no
src/main/groovy/**/SecurityConfig.groovy:Also
user.rocker.rawmarks thepasswordfield with thepasswordconstraint, so scaffolding renders it masked rather than as plain text:Testing
SpringBootStarterSecuritySpecasserts the DSL inApplication.groovy, that noSecurityConfig.groovyis generated, the new authorization rules, and the new constraint. The negative case asserts neitherdef beans = {nor@EnableWebSecurityappears without the feature.:grails-forge-core:test— 322 tests, 0 failures, 1 skippedRendered output was inspected directly for both the secured and unsecured variants.
Not covered here: the tests assert on generated text; no generated project was compiled and booted. That is worth a reviewer's attention on the second change in particular — a lockdown default can break a generated starter on first run in a way
permitAllcould not, if some path the welcome page needs is missing from the permit list.